<template>
  <div class="header">
    <van-icon name="arrow-left" class="icon" @click="toBack"></van-icon>
    <div>{{ title }}</div>
    <div class="edit" v-if="edit" @click="handleChange">{{ store.state.edit ? '编辑' : '完成' }}</div>
  </div>
</template>

<script setup>
import {defineProps} from 'vue'
import {useRouter} from "vue-router";
import {useStore} from "vuex";
import {Toast} from "vant";

const props = defineProps(['title','edit'])

const store = useStore()
const router = useRouter()
const toBack = () => {
  router.back()
}

const handleChange = () => {
  if(store.state.cartList.length){
    store.commit('edit')
    store.commit('changeDelete')
  }else{
    Toast.fail('请先添加商品')
  }
}

</script>


<style lang="less" scoped>
.header {
  background-color: #fff;
  height: 40px;
  font-size: 20px;
  display: flex;
  justify-content: center;
  align-items: center;
  border-bottom: 1px solid #d7d7d7;

  .edit {
    font-size: 16px;
    position: absolute;
    right: 15px;
    font-weight: normal;
  }

  .icon {
    position: absolute;
    left: 10px;
  }
}
</style>